public class Solution {
    public int search(int[] nums, int target) {
        int k = nums[0];
        int flag1 = binarySearch(nums, 0, k - 1, target);
        if (flag1 != -1) {
            return flag1;
        }
        int flag2 = binarySearch(nums, k, nums.length - 1, target);
        if (flag2 != -1) {
            return flag2;
        }
        return -1;
    }

    public int binarySearch(int[] nums, int start, int end, int value) {
        if (0 <= start && start < nums.length
                && 0 <= end && end < nums.length) {
            while (start <= end) {
                int mid = (start + end) >>> 1;
                int midValue = nums[mid];
                if (value < midValue) {
                    end = mid - 1;
                } else if (midValue < value) {
                    start = mid + 1;
                } else {
                    return mid;
                }
            }
        }

        return -1;
    }

}
